package org.jxf.zhaohuo.plugin;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.Intent;

public class Share extends CordovaPlugin { 
	 
    @Override 
    public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) { 
        PluginResult result = new PluginResult(PluginResult.Status.OK, "");
        try { 
            JSONObject jo = args.getJSONObject(0); 
            String subject = jo.getString("subject");
            String text = jo.getString("text");
            Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND); 
            sendIntent.setType("text/plain"); 
            sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject); 
            sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, text); 
            this.cordova.startActivityForResult(this, sendIntent, 0); 
            
            callbackContext.sendPluginResult(result);
            callbackContext.success();
            return true; 
        } catch (JSONException e) { 
            result = new PluginResult(PluginResult.Status.JSON_EXCEPTION, "JSON Exception");
            callbackContext.sendPluginResult(result);
            return false;
        } 
    } 
     
 
 
} 
